<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="urn:mockingbird.engine.business.configuration:handlerconfiguration" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:mockingbird.engine.business.configuration:handlerconfiguration" elementFormDefault="qualified" id="XMLSchema">
	<xs:simpleType name="ResponseStrategyType">
		<xs:annotation>
			<xs:documentation>Strategy for picking up the response - could be Default or XPath</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
          <xs:enumeration value="Default"/>
          <xs:enumeration value="XPath"/>
          <xs:enumeration value="Xslt"/>
          <xs:enumeration value="None"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ResponseBehaviourType">
		<xs:annotation>
			<xs:documentation>Type of response behavior  - Standard, Error Or Variable</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
          <xs:enumeration value="Standard"/>
          <xs:enumeration value="Error"/>
          <xs:enumeration value="Variable"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ErrorType">
		<xs:annotation>
			<xs:documentation>What type of error do we wish to return</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:enumeration value="SoapFault"/>
			<xs:enumeration value="Timeout"/>
			<xs:enumeration value="None"/>
		</xs:restriction>
	</xs:simpleType>

  <!--BEGIN Request SOAP headers types-->
  
  <xs:complexType name="RequestSoapHeadersType">
    <xs:annotation>
      <xs:documentation>Define list of SOAP request headers and simulation options</xs:documentation>
      <xs:documentation>Option exists to set response headers from file</xs:documentation>
    </xs:annotation>
    <xs:sequence minOccurs="0">
      <xs:element name="EchoRequestHeaders">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Match" type="RequestHeaderType" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="SetResponseHeaderFromThisFilePath" type="xs:string" use="optional" />
  </xs:complexType>
                  
  <xs:complexType name="RequestHeaderType">
    <xs:annotation>
      <xs:documentation>The name of the request header with optional list of xpaths from which to extract response header values</xs:documentation>
    </xs:annotation>
    <xs:sequence minOccurs="0">
      <xs:element name="Xpaths" type="RequestHeaderValueXpathsType"/>
      <xs:element name="ResponseHeaderXml">
        <xs:complexType>
          <xs:annotation>
            <xs:documentation>Corresponding response header name and optional xml content</xs:documentation>
          </xs:annotation>
          <xs:sequence>
            <xs:any minOccurs="0" processContents="skip"/> 
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="RequestHeaderName" type="xs:string" use="required"/>
  </xs:complexType>
  
  <xs:complexType name="RequestHeaderValueXpathsType">
    <xs:annotation>
      <xs:documentation>Collection of xpaths to be run against request SOAP header</xs:documentation>
    </xs:annotation>
    <xs:sequence minOccurs="1" >
      <xs:annotation>
        <xs:documentation>Each xpath should yield a value to be inserted into corresponding response header
        NOTE: The order of the xpaths is important! If formatter is used in the xml template [ResponseHeaderXml] the order of the
        xpath needs to follow the order of the format</xs:documentation>
      </xs:annotation>
      <xs:element name="HeaderValueXpath" type="xs:string" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  
  <!--END Request SOAP headers types-->
  
  <xs:complexType name="ResponseType">
		<xs:annotation>
			<xs:documentation>Structure of a response element</xs:documentation>
		</xs:annotation>
		<xs:attribute name="ResponseBehaviour" type="ResponseBehaviourType" use="required">
			<xs:annotation>
				<xs:documentation>How the system behaves. Controlled by the ResponsebehaviorType enumerations</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="FileName" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>ResponseFile to use (unless its a timeout</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="ErrorType" type="ErrorType" use="required">
			<xs:annotation>
				<xs:documentation>Type of error to be thrown.Should be set to None if the behavior is Standard. Controlled by the ErrorTypeType enumerations</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>
	
  <xs:complexType name="XPathBasedResponseType">
		<xs:annotation>
			<xs:documentation>Structure of an XPath Query</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="Expression" type="xs:string"/>
			<xs:element name="Result" type="xs:string"/>
			<xs:element name="Response" type="ResponseType"/>
		</xs:sequence>
	</xs:complexType>
  
	<xs:complexType name="XPathBasedResponsesType">
		<xs:annotation>
			<xs:documentation>Collection of XPathQuery based responses</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="XPathBasedResponse" type="XPathBasedResponseType" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>

  <xs:complexType name="OperationMapEntryType">
    <xs:annotation>
      <xs:documentation>Maps some data to a corresponding operation</xs:documentation>
    </xs:annotation>
    <xs:attribute name="Key" type="xs:string">
      <xs:annotation>
        <xs:documentation> Key for the map entry (example:soap action)</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="OperationName" type="xs:string">
      <xs:annotation>
        <xs:documentation>Name of the operation involved.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="OperationMapType">
    <xs:annotation>
      <xs:documentation>Collection of entries mapping data to operations.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Map" type="OperationMapEntryType" minOccurs="0" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="OperationType">
    <xs:annotation>
      <xs:documentation>Structure of an operation</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="SoapHeaderConfiguration" type="RequestSoapHeadersType" minOccurs="0" />
      <xs:choice minOccurs="0" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>This choice is governed by the ResponseStrategy. If ResponseStrategy is None, then this wont be present because it indicates a one way operation. Otherwise its a choice between a default response or a collection of XPathResponses  (which in turn have associaed expressions, result and responses/.</xs:documentation>
        </xs:annotation>
        <xs:element name="DefaultResponse" type="ResponseType">
          <xs:annotation>
            <xs:documentation>DefaultResponse. Corresponds to ResponseStrategy = Default</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="XsltBasedResponse" type="ResponseType">
          <xs:annotation>
            <xs:documentation>An XSLT based response. Response will be generated by applying XSLT to the request.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="XPathBasedResponses" type="XPathBasedResponsesType">
          <xs:annotation>
            <xs:documentation>Collection of candidate responses each associated with an XPath Expression.This corresponds to ResponseStrategy = XPath</xs:documentation>
          </xs:annotation>
        </xs:element>
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>Name of the Operation</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="ResponseStrategy" type="ResponseStrategyType" use="required">
      <xs:annotation>
        <xs:documentation>Strategy for selecting a response</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="SoapAction" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation>SoapAction that corresponds to the operation</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:element name="HandlerConfiguration">
		<xs:annotation>
			<xs:documentation>Root Element holding all settings for the handler</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Wsdl" type="xs:string" minOccurs="0">
					<xs:annotation>
						<xs:documentation>The name of a Wsdl document in the Wsdl folder ie "CIGateway.wsdl"</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="ControlSettings">
					<xs:annotation>
						<xs:documentation>Settings which control the working of the handler</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element name="OperationNameInferenceStrategy">
								<xs:annotation>
									<xs:documentation>The approach to use for inferring the name of the current operation  </xs:documentation>
								</xs:annotation>
								<xs:simpleType>
									<xs:restriction base="xs:string">
                    <xs:enumeration value="SoapAction">
                      <xs:annotation>
                        <xs:documentation>Operation name is extracted directly from the end segment of the soapAction</xs:documentation>
                      </xs:annotation>
                    </xs:enumeration>
                    <xs:enumeration value="QueryString">
                      <xs:annotation>
                        <xs:documentation>Operation name is extracted from the query string </xs:documentation>
                      </xs:annotation>
                    </xs:enumeration>
                    <xs:enumeration value="SoapActionOperationMap">
                      <xs:annotation>
                        <xs:documentation>There is a mapping between the soapAction and the operation so the soapaction attribute alongside the
                        operation element is ignored and this is used instead.
                      </xs:documentation>
                      </xs:annotation>
                    </xs:enumeration>
                    <xs:enumeration value="RequestRootElementOperationMap">
                      <xs:annotation>
                        <xs:documentation>
                          There is a mapping between the root element of the request and the operation and so the
                          soap action is ignored.
                        </xs:documentation>
                      </xs:annotation>
                    </xs:enumeration>

                  </xs:restriction>
								</xs:simpleType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
        <xs:element name="SoapActionOperationMap" type="OperationMapType" minOccurs="0" maxOccurs="1">
          <xs:annotation>
            <xs:documentation>Maps the soap actions to corresponding operations.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element name="RequestRootElementOperationMap" type="OperationMapType" minOccurs="0" maxOccurs="1">
          <xs:annotation>
            <xs:documentation>Maps the root elements of the requests to corresponding operations.</xs:documentation>
          </xs:annotation>
        </xs:element>
				<xs:element name="Operations">
					<xs:annotation>
						<xs:documentation>A collection of operations exposed at this endpoint</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Operation" type="OperationType" maxOccurs="unbounded">
								<xs:annotation>
									<xs:documentation>A single operation</xs:documentation>
								</xs:annotation>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
      </xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
